import { Success } from 'lin-mizar';

export const successData = (app) => {
  app.context.successData = function (data, ex = 0) {
    this.type = 'application/json';
    const success = new Success(ex);
    this.status = success.status;
    const dataInfo = {
      code: success.code,
      data,
      message: success.message,
      request: `${this.method} ${this.req.url}`
    };
    this.body = JSON.stringify(dataInfo);
  };
};